package com.ssm.platform.pojo.param;

import com.ssm.basis.model.pojo.param.BaseParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

/**
 * validation 示例
 *
 * @see MethodValidationPostProcessor
 * @see NotNull 用在所有类型上面，不能为 null
 * @see NotEmpty String、Collection、Map、Array、(不能注释枚举)，不能为 null 或者长度为 0(isEmpty())
 * @see NotBlank 用在 String 上面，和 NotEmpty 不同的是，尾部空格被忽略，也就是说，纯空格的 String 也是不符合规则的
 */
@Getter
@Setter
@ToString
public class ValidationParam extends BaseParam {
    private static final long serialVersionUID = 1L;

    @NotBlank
    @Schema(description = "姓名")
    private String fullName;

    @NotNull
    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @NotEmpty(message = "问答详情不能为空")
    @Schema(description = "问答详情")
    private List<@Valid @NotNull ValidationDetailParam> validationDetailParas;

    @Data
    @Accessors(chain = true)
    @EqualsAndHashCode(callSuper = false)
    @Schema(description = "验证详情参数")
    static class ValidationDetailParam extends BaseParam {
        private static final long serialVersionUID = 1L;

        @NotBlank(message = "问题不能为空")
        @Schema(description = "问题")
        private String question;

        @Schema(description = "回答")
        private String answer;
    }
}
